{extend name="public/father" /}

{block name='main'}
<div class="layui-card">

    <div class="layui-inline" style="margin-top: 20px">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" id="username" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-primary" lay-filter="data-search-btn" id="searchBtn"><i class="layui-icon"></i> 搜 索</button>
        </div>
        <button class="layui-btn" id="confirm_sync"><i class="layui-icon layui-icon-addition"></i>确认同步</button>
    </div>
<!--    <div class="layui-card-header">-->
<!--        <button class="layui-btn" id="confirm_sync"><i class="layui-icon layui-icon-addition"></i>确认同步</button>-->
<!--    </div>-->
    <div class="layui-card-body">
        <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
        <script type="text/html" id="barDemo">
            <div class="layui-btn-group">
                <a class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修改</a>
            </div>
        </script>

        <script type="text/html" id="admin">
        {{ d.admin == 1 ? '管理员' : '' }}
        {{ d.admin == 2 ? 'VIP用户' : '' }}
        {{ d.admin == 3 ? '代理' : '' }}
        {{ d.admin == 4 ? '视频管理' : '' }}
        </script>

    </div>
</div>
{/block}


{block name="js"}
<script type="text/javascript">
    layui.use(['table', 'layer', 'form'], function() {
        let $ = layui.jquery, table = layui.table, form = layui.form;
        table.render({
            elem: '#dataTable',
            url: "{:url()}?so={:trim(input('param.so'))}&video_ids={:trim(input('param.video_ids'))}",
            title: '数据表',
            cellMinWidth: 200,
            limit: 100,
            size: 'lg',
            cols: [[
                {type: "checkbox"},
                {field: 'username',	title:'用户名',	minWidth:200,	align:'center',	sort:true},
	            {field: 'admin',	title:'权限',	width:100,	align:'center',	sort:true,		templet:'#admin'},
	            {field: 'end_time',	title:'到期时间',		width:170,templet: "<div>{{layui.util.toDateString(d.end_time*1000, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
            ]],
            page: true
        });
        $("#searchBtn").on("click", function() {
            let username = $("#username").val();
            table.reload("dataTable", {
                where: {
                    "username": username
                }
            });
        });

        $("#confirm_sync").on("click", function() {
            var video_ids = "{:trim(input('param.video_ids'))}";
            var checkStatus = table.checkStatus('dataTable');
            var ids = [];
            $(checkStatus.data).each(function (i, o) {
                ids.push(o.id);
            });
            if (ids.length < 1) {
                layer.msg('无选中项');
                return false;
            }
            ids = ids.join(",");
            $.ajax({
                url: "/admin/video/sync",
                type: "post",
                data: {
                    "ids": ids,
                    "video_ids": video_ids
                },
                success:function(res){
                    if(res.code==0){
                        layer.msg("同步成功")
                    }else{
                        layer.msg("同步失败")
                    }
                }
            })
        });

    });

</script>
{/block}
